from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid
from OCC.Core.BRepGProp import brepgprop_VolumeProperties
from OCC.Core.GProp import GProp_GProps
from OCC.Core.TopAbs import TopAbs_SHELL
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopoDS import topods
from OCC.Display.SimpleGui import init_display
from OCC.Extend.DataExchange import read_stl_file


def calc_volume(shape):
    props = GProp_GProps()
    brepgprop_VolumeProperties(shape, props)
    return props.Mass()


shapes = read_stl_file('./ceshi.STL')

explorer = TopExp_Explorer(shapes, TopAbs_SHELL)

boxes = []

while explorer.More():
    shell = topods.Shell(explorer.Current())
    ms = BRepBuilderAPI_MakeSolid()
    ms.Add(shell)
    boxes.append(ms.Solid())
    explorer.Next()

display, start_display, add_menu, add_function_to_menu = init_display()

for box in boxes:
    print(type(box))
    display.DisplayShape(box)

# display.DisplayShape(shapes)
# display.DisplayShape(my_ball)
# display.DisplayShape(my_ball_result)


# display.DisplayShape(my_box)
# display.DisplayShape(result)


# ais_context = display.GetContext()
# ais_context.Display(my_ball_ais_shp, True)
# display.View_Iso()

start_display()
